Skip to content

fix(node-api): unbounded filter input#3102

Open
bar-bera wants to merge 3 commits into
mainfrom
claude-security-fixes/unbounded-val-filter
Open

fix(node-api): unbounded filter input#3102
bar-bera wants to merge 3 commits into
mainfrom
claude-security-fixes/unbounded-val-filter

Conversation

@bar-bera
Copy link
Copy Markdown
Collaborator

Unbounded input in API request

  • POST /eth/v1/beacon/states/{state_id}/validators
  • POST /eth/v1/beacon/states/{state_id}/validator_balances

causes O(N*M) algorithmic complexity DoS with

  • N validator registry (not set) size
  • M attacker slice size (indices or pubkeys)

With Berachain registry size < 100 impact is minimal.

Fix

  • Cap on inputs
  • Filter implementation by mapping instead of arrays.

  ### Cause
  Unbounded input in API request
  * `POST /eth/v1/beacon/states/{state_id}/validators`
  * `POST /eth/v1/beacon/states/{state_id}/validator_balances`

  ### Issue
  O(N*M) algorithmic complexity DoS with
  * N validator registry (not set) size
  * M attacker slice size (indices or pubkeys)

  ### Impact
  With Berachain reduced validator set (N_registry ~= 100) lower impact than stated.
  Server work per request at N=100:
  * Numeric path, M=100k: ~10⁷ uint64 compares ≈ ~10 ms CPU.
  * Pubkey path, M=100k: ~10⁷ × 48-byte memcmp ≈ ~100–500 ms CPU.

  Impact is worse for `validator_balances` (state read).

  ### Likelyhood
  Unauth request. Cost in bandwidth:

  | Field type | Per-entry bytes (JSON) | M=10^5 body | M=10^6 body |
  |---|---|---|---|
  | Numeric ID `"12345"` | ~7–9 | ~800 KB | ~8 MB |
  | Hex pubkey `"0x"` + 96 hex | ~102 | ~10 MB | ~100 MB |

  ### Fix
  * Cap on inputs
  * Filter implementation by mapping instead of arrays.
Copilot AI review requested due to automatic review settings May 11, 2026 12:37
@bar-bera bar-bera requested a review from a team as a code owner May 11, 2026 12:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR mitigates an algorithmic-complexity DoS vector in the beacon node API validator-filtering endpoints by bounding filter input sizes and reducing per-validator filter-matching work.

Changes:

  • Reworked validator ID/pubkey matching from linear slices.Contains checks to O(1) map lookups.
  • Added request validation caps for IDs/statuses on /validators and IDs on /validator_balances.
  • Added constants for the caps and a test covering the /validators ID cap.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
node-api/handlers/beacon/validators_filters.go Switches validator filter membership checks from slices to maps to avoid O(N*M) behavior.
node-api/handlers/beacon/validators_filters_test.go Adds a test asserting requests over the max IDs cap are rejected.
node-api/handlers/beacon/types/request.go Enforces per-request caps via struct-tag validation on validator IDs/statuses.
node-api/handlers/beacon/types/limits.go Introduces named constants for request caps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread node-api/handlers/beacon/types/limits.go Outdated
Comment thread node-api/handlers/beacon/types/request.go
@bar-bera bar-bera requested a review from a team May 13, 2026 08:42
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.24%. Comparing base (ffe5e16) to head (ea051d2).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3102      +/-   ##
==========================================
+ Coverage   61.21%   61.24%   +0.03%     
==========================================
  Files         369      369              
  Lines       18925    18927       +2     
==========================================
+ Hits        11584    11592       +8     
+ Misses       6382     6378       -4     
+ Partials      959      957       -2     
Files with missing lines Coverage Δ
node-api/handlers/beacon/validators_filters.go 85.00% <100.00%> (+0.30%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread node-api/handlers/beacon/types/limits.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants